package com.spzx.product.controller;

import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.exception.ServiceException;
import com.spzx.product.domain.SkuLockVo;
import com.spzx.product.service.SkuStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * BelongProject: spzx-parent
 * BelongPackage: com.spzx.product.controller
 * Description:
 *
 * @Author 段鑫涛
 * @Create 2025/6/7 0:12
 * @Version 1.0
 */
@RestController
@RequestMapping("/skuStock")
public class SkuStockController {

    @Autowired
    private SkuStockService skuStockService;

    @PostMapping(value = "/checkAndLockStock/{tradeNo}")
    R<String> checkAndLockStock(@PathVariable("tradeNo")String tradeNo, @RequestBody List<SkuLockVo> skuLockVos){
        try {
            return R.ok(skuStockService.checkAndLockStock(tradeNo, skuLockVos));
        } catch (ServiceException e) {
            e.printStackTrace();
            return R.ok(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return R.ok("库存不足");
        }
    }
}
